package com.rainng.coursesystem.service;

import com.rainng.coursesystem.model.CourseNotificationItem;
import com.rainng.coursesystem.repository.CourseNotificationRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class CourseNotificationService {

    @Autowired
    private CourseNotificationRepository courseNotificationRepository;

    public List<CourseNotificationItem> getNotificationsByCourseId(Long courseId) {
        return courseNotificationRepository.findByCourseIdOrderByCreatedAtDesc(courseId);
    }

    public CourseNotificationItem createNotification(CourseNotificationItem notification) {
        return courseNotificationRepository.save(notification);
    }

    public boolean deleteNotification(Long id) {
        if (courseNotificationRepository.existsById(id)) {
            courseNotificationRepository.deleteById(id);
            return true;
        }
        return false;
    }

    // 可以根据需要添加更多方法
}